#include "Stage.h"


Stage::Stage()
{
	blocks = std::list<Block>();
	width = height = 0;
	startx = starty = 0;
}

bool Stage::LoadStage(std::string filename, engine e)
{
	std::ifstream stage;
	stage.open(filename.c_str());

	if(!stage.is_open())
	{
		stage.close();
		return false;
	}

	std::string s = "";
	std::string f = "";
	int x,y,w,h;
	while(stage.eof() == false)
	{

		x = y = w = h = 0;

		stage >> s;

		if(stage.fail() == true)
		{
			stage.close();
			return false;
		}

		if(s == "Block")
		{
			stage >> x >> y >> w >> h >> f;
			blocks.push_back(Block(x, y, w, h, e.load_image(f)));
		}
		else if(s == "Dimensions")
		{
			stage >> width >> height;
		}
		else if(s == "End")
		{
			stage >> x >> y >> w >> h >> f;
			end(x, y, w, h, e.load_image(f.c_str()));
		}
		else if(s == "Start")
		{
			stage >> startx >> starty;
		}
		else
		{
			stage.close();
			return false;
		}

	}

}

std::list<Block> Stage::getBlocks()
{
	return blocks;
}

void Stage::Update(Uint32 dticks)
{
	for(Block b : blocks)
	{
		b.Update(dticks);
	}
}
